#include "lua_c_api/include/lua.hpp"
#include "reaper_plugin/reaper_plugin.h"

#define REALUA_VERSION	"1.0.0.B0"	// Beta zero that will be version 1.0.0

// checks the function pointer (genericized to void *) for
// null, will print error message including the fname
// if the function pointer is null

bool checkFunc(void *fp, char *fname);

// opposite sense version for "assert"-ive syntax
bool badFunc(void *fp, char *fname);

// typo-reduction version of previous checkFunc():

#define checkFunctionPointer(NAME)	checkFunc( NAME , #NAME )

#define assertFunc(FP,FN)				\
	if( badFunc( FP , FN ) )	return 0;		// erring out

// typo-reduction version of assertFunc():

#define assertFunctionPointer(NAME)	assertFunc( NAME , #NAME )

// fills all the reaper_plugin_function				( is there already one of
// pointers declared in ^r_p_f^ dot-h:				( these somewhere?

void initFunctionPointers(reaper_plugin_info_t *rec);

// fills a Lua table named "reaper"
// with the function pointers initialized
// by the aforementioned initFunctionPointers(rec):

void reaperMainTable(lua_State *L);

// adds a new named number to the table at the top of the stack

void reaperNumberConstant(lua_State *L, const char *name, double val);

// adds a new named boolean to the table at the top of the stack

void reaperBoolConstant(lua_State *L, const char *name, bool val);

// adds a new named string to the table at the top of the stack

void reaperStringConstant(lua_State *L, const char *name, const char *val);

// makes a NEW table in the current table
// leaves NEW table on stack so it can have stuff stuffed into it:

void reaperTable(lua_State *L, const char *name);

// famous helper function from PIL:

void stackDump (lua_State *L);





void reaperSubTables(lua_State *L);

#define BUFSIZE	(128)
#define BIGBUF	(32768)

#define challoc(S) \
	(char *) malloc(S)

// to keep luaL rhyme scheme intact:

inline bool checkbool(lua_State *L, int idx)
{
	luaL_checktype(L, idx, LUA_TBOOLEAN);
	return ( lua_toboolean(L, idx) != 0 );
}

#define luaL_checkboolean checkbool


